package com.tan.websocket.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author Tan
 * @description
 * @date 2025/1/26
 */
@Slf4j
@Service
public class FramePingService extends MainFrameAbstractService  {
    @Override
    public void handleMessage(ChannelHandlerContext ctx, WebSocketFrame frame) {
        log.info("收到ping帧====");
        ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
    }

    @Override
    public boolean isFrameType(WebSocketFrame frame) {
        return frame instanceof PingWebSocketFrame;
    }

    @Override
    public String serviceName() {
        return PingWebSocketFrame.class.getSimpleName();
    }
}
